package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.bbs.model.Board;
import com.msmall.community.bbs.model.Master;
import com.msmall.community.bbs.service.MasterManager;


public class BbsMasterAction extends HTMLBaseAction {

	private static final long serialVersionUID = 4641217222398716879L;

	private Long boardId;
	
	private String masterIds;
	/**
	 * 设置版主时，传递过来的用户ID
	 */
	private Long setid; 
	
	/**
	 * 1用户名 2用户昵称 3用户手机号码
	 */
	private String searchType;
	
	private String searchValue;
	
	/**
	 * 版主级别
	 */
	private String level;
	
	private String toUrl;
	
	private Master master;
	
	private Board board;
	
	private MasterManager masterManager;
	
	/**
	 * 版主管理首页
	 * @return
	 */
	public String index(){
		page.setClazz(Master.class);
		page.setPageSize(10);
		String queryString = "from Master m where m.boardId = " + boardId + " order by masterId asc";
		page.setQueryString(queryString);
		masterManager.getPagination(page);
		page.setUrl(ConstantUrl.ADMIN_BOARD_MASTER_INDEX+"?boardId="+boardId);
		return "index";
	}
	/**
	 * 进入添加版主页面
	 * @return
	 */
	public String create(){
		board = (Board) masterManager.get(Board.class, boardId);
		return "create";
	}
	/**
	 * 删除版主
	 * @return
	 */
	public String delete(){
		masterManager.delete(masterIds);
		toUrl = "/admin/bbs/masterIndex.do?boardId=" + boardId;
		this.setToUrl(toUrl);
		return "index";
	}

	/**
	 * 添加版主时，搜索用户信息
	 * @return
	 */
	public String search(){
		masterManager.search(page, searchType, searchValue);
		board = (Board) masterManager.get(Board.class, boardId);
		return "search";
	}
	
	/**
	 * 设置版主
	 * @return
	 */
	public String setMaster(){
		masterManager.setMaster(boardId, setid,level);
		toUrl = "/admin/bbs/masterIndex.do?boardId=" + boardId;
		this.setToUrl(toUrl);
		return SUCCESS;
	}
	/*
	public String save(){
		toUrl = "/admin/bbs/masterIndex.do?boardId=" + boardId;
		this.setToUrl(toUrl);
		return SUCCESS;
	}
	*/
	public Long getBoardId() {
		return boardId;
	}

	public void setBoardId(Long boardId) {
		this.boardId = boardId;
	}

	public Long getSetid() {
		return setid;
	}
	public void setSetid(Long setid) {
		this.setid = setid;
	}
	public String getMasterIds() {
		return masterIds;
	}

	public void setMasterIds(String masterIds) {
		this.masterIds = masterIds;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	public String getSearchValue() {
		return searchValue;
	}

	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}

	public String getLevel() {
		return level;
	}
	public void setLevel(String level) {
		this.level = level;
	}
	public String getToUrl() {
		return toUrl;
	}

	public void setToUrl(String toUrl) {
		this.toUrl = toUrl;
	}

	public Master getMaster() {
		return master;
	}

	public void setMaster(Master master) {
		this.master = master;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	public void setMasterManager(MasterManager masterManager) {
		this.masterManager = masterManager;
	}
	
}
